<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../css/style.css">
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <script src="../js/vue.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
        <script src="../js/echarts.js"></script>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>统计分析<small>会员数量</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>统计分析</el-breadcrumb-item>
                    <el-breadcrumb-item>会员数量</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <template>
                    <div class="block">
                    <el-date-picker
                            v-model="value1"
                            type="daterange"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            @change="getMemberReport">
                    </el-date-picker>
                    </div>
                    </template>
                </div>
            </div>
        </div>

        <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
        <div id="chart1" style="height:600px;"></div>

        <div class="box"></div>
        <div id="char2" style="height: 400px;"></div>

    </body>
    <!-- 引入组件库 -->
    <script type="text/javascript">

        new Vue({
            el:"#app",
            data:{
                value1:null
            },
            methods:{
                getMemberReport(){
                    let param = {};
                    if (this.value1){
                        let start = this.value1[0];
                        let end = this.value1[1];
                        param.start = start;
                        param.end = end;
                    }
                    // 基于准备好的dom，初始化echarts实例
                    var myChart1 = echarts.init(document.getElementById('chart1'));
                    // 使用刚指定的配置项和数据显示图表。
                    //myChart.setOption(option);
                    axios.post("/report/getMemberReport.do",param).then((response)=>{
                        console.log(response);
                        myChart1.setOption({
                            title: {
                                text: '会员数量'
                            },
                            tooltip: {},
                            legend: {
                                data:['会员数量']
                            },
                            xAxis: {
                                data: response.data.data.months
                            },
                            yAxis: {
                                type:'value'
                            },
                            series: [{
                                name: '会员数量',
                                type: 'line',
                                data: response.data.data.memberCount
                            }]
                        });
                    });
                }
            },
            created(){
                this.getMemberReport();
            }

        });


        // 基于准备好的dom，初始化echarts实例
        var myChart2 = echarts.init(document.getElementById('char2'));
        axios.get("/report/getMemberProportion.do").then((response)=>{
            myChart2.setOption({
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b}: {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    x: 'left'
                },
                series: [
                    {
                        name:'访问来源',
                        type:'pie',
                        selectedMode: 'single',
                        radius: [0, '30%'],

                        label: {
                            normal: {
                                position: 'inner'
                            }
                        },
                        labelLine: {
                            normal: {
                                show: false
                            }
                        },
                        data:
                        response.data.data.list

                    },
                    {
                        name:'会员数量组成',
                        type:'pie',
                        radius: ['40%', '55%'],
                        label: {
                            normal: {
                                formatter: '{a|{a}}{abg|}\n{hr|}\n  {b|{b}：}{c}  {per|{d}%}  ',
                                backgroundColor: '#eee',
                                borderColor: '#aaa',
                                borderWidth: 1,
                                borderRadius: 4,
                                rich: {
                                    a: {
                                        color: '#999',
                                        lineHeight: 22,
                                        align: 'center'
                                    },

                                    hr: {
                                        borderColor: '#aaa',
                                        width: '100%',
                                        borderWidth: 0.5,
                                        height: 0
                                    },
                                    b: {
                                        fontSize: 16,
                                        lineHeight: 33
                                    },
                                    per: {
                                        color: '#eee',
                                        backgroundColor: '#334455',
                                        padding: [2, 4],
                                        borderRadius: 2
                                    }
                                }
                            }
                        },
                        data:
                        response.data.data.mapList
                    }
                ]
            })
        });

    </script>
</html>
